package com.huawei.appgallery.forum.message.card;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.CommentReference;
import com.huawei.appgallery.forum.base.card.bean.ImageInfo;
import com.huawei.appgallery.forum.base.card.bean.Post;
import com.huawei.appgallery.forum.base.card.bean.PostTime;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.cards.widget.FoldTextView;
import com.huawei.appgallery.forum.cards.widget.FoldTextView.e;
import com.huawei.appgallery.forum.message.bean.ForumRemindCommentCardBean;
import com.huawei.appgallery.forum.message.widget.CommentReferenceUserView;
import com.huawei.appgallery.forum.message.widget.CommentReferenceView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.List;
import java.util.Locale;
import o.azb;
import o.bqx;
import o.bqz;
import o.bse;
import o.bsx;
import o.btc;
import o.btl;
import o.btu;
import o.bvj.a;
import o.bvj.b;
import o.bvj.c;
import o.bvj.d;
import o.bvj.j;
import o.bwy;
import o.cbb;
import o.cgz;
import o.cil;
import o.cim;
import o.ContentManager;
import o.eqx;
import o.evk;
import o.evx;
import o.hb;

public class ForumRemindCommentCard extends ForumCard implements OnClickListener, btl {
    private int ʻ;
    private View ʼ;
    private Post ʽ;
    private ImageView ˊ;
    private CommentReferenceView ˋ;
    private String ˋॱ = "";
    private TextView ˎ;
    private CommentReferenceUserView ˏ;
    private boolean ˏॱ = false;
    private String ͺ;
    private FoldTextView ॱ;
    private long ॱˊ = 0;
    private User ॱॱ;
    private ForumRemindCommentCardBean ᐝ;

    public ForumRemindCommentCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        ʽ(view);
        azb.ˏ(view, b.ˉ);
        this.ˏ = (CommentReferenceUserView) view.findViewById(b.ˏ);
        this.ˏ.setUserContentClickLisenter(this);
        this.ॱ = (FoldTextView) view.findViewById(b.ʻᐝ);
        this.ˊ = (ImageView) view.findViewById(b.ʼˊ);
        this.ˎ = (TextView) view.findViewById(b.ʻˊ);
        this.ˎ.setOnClickListener(this);
        ((ImageView) view.findViewById(b.ʻˋ)).setOnClickListener(new evx(this) {
            final /* synthetic */ ForumRemindCommentCard ˏ;

            {
                this.ˏ = r1;
            }

            public void ˋ(View view) {
                this.ˏ.ˋ(view);
            }
        });
        this.ˋ = (CommentReferenceView) view.findViewById(b.ˊ);
        this.ʼ = view.findViewById(b.ॱ);
        this.ʼ.setVisibility(8);
        ((LinearLayout) view.findViewById(b.ˎ)).setOnClickListener(new evx(this) {
            final /* synthetic */ ForumRemindCommentCard ˋ;

            {
                this.ˋ = r1;
            }

            public void ˋ(View view) {
                this.ˋ.ॱ(false);
            }
        });
        this.ॱ.setOnClickListener(new evx(this) {
            final /* synthetic */ ForumRemindCommentCard ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(View view) {
                this.ˊ.ॱ(false);
            }
        });
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof ForumRemindCommentCardBean) {
            ForumRemindCommentCardBean forumRemindCommentCardBean = (ForumRemindCommentCardBean) cardBean;
            this.ᐝ = forumRemindCommentCardBean;
            ॱ(forumRemindCommentCardBean);
        }
    }

    private void ॱ(ForumRemindCommentCardBean forumRemindCommentCardBean) {
        int i = 0;
        if (forumRemindCommentCardBean.ˋॱ()) {
            this.ʼ.setVisibility(0);
        } else {
            this.ʼ.setVisibility(8);
        }
        this.ʻ = forumRemindCommentCardBean.ॱˊ();
        this.ॱॱ = forumRemindCommentCardBean.ˊ();
        this.ͺ = forumRemindCommentCardBean.ॱ();
        this.ˏ.setDomainId(this.ͺ);
        if (this.ॱॱ != null) {
            this.ˏ.setUser(this.ॱॱ);
        }
        ʽ();
        this.ʽ = forumRemindCommentCardBean.ᐝ();
        if (this.ʽ != null) {
            ॱॱ();
            PostTime ˎ = this.ʽ.ˎ();
            if (ˎ != null) {
                this.ˏ.setSectionName(btc.ˏ(this.ʼॱ, ˎ));
            }
        } else {
            ʼ();
            this.ˏ.setSectionName(null);
            this.ॱ.setText(bse.ˏ.ॱ(400012).ˎ());
        }
        CommentReference ʼ = forumRemindCommentCardBean.ʼ();
        if (ʼ != null) {
            this.ˋॱ = ʼ.ʽ();
            if (!(this.ˋॱ == null || this.ˋॱ.contains("app_detail_comment") || this.ˋॱ.contains("app_detail_reply"))) {
                i = 1;
            }
            if (i != 0 && this.ˋॱ.contains(HiAnalyticsConstant.REPORT_VAL_SEPARATOR)) {
                try {
                    this.ॱˊ = Long.parseLong(this.ˋॱ.substring(this.ˋॱ.lastIndexOf(HiAnalyticsConstant.REPORT_VAL_SEPARATOR) + 1));
                } catch (NumberFormatException e) {
                    bqx.ˋ("ForumRemindCommentCard", "Parse detail id NumberFormatException");
                }
            }
            ʼ.ˊ(ˎ());
        }
        this.ˋ.setPostTitleWidth(((azb.ॱ(this.ʼॱ) - this.ʼॱ.getResources().getDimensionPixelSize(d.ˊॱ)) - this.ʼॱ.getResources().getDimensionPixelSize(d.ʼ)) - this.ʼॱ.getResources().getDimensionPixelSize(d.ʽ));
        this.ˋ.setReference(ʼ);
        this.ˋ.setDomainId(forumRemindCommentCardBean.ॱ());
    }

    private int ˎ() {
        switch (this.ʻ) {
            case 1:
                return 1;
            case 2:
                return 2;
            case 3:
                return 3;
            case 4:
                return 4;
            case 5:
                return 5;
            default:
                return 0;
        }
    }

    private void ʽ() {
        this.ॱ.setVisibility(0);
        this.ˊ.setVisibility(8);
        this.ˎ.setVisibility(8);
        this.ˏॱ = false;
        this.ॱ.setCompoundDrawables(null, null, null, null);
    }

    @TargetApi(21)
    private void ॱॱ() {
        if (this.ʽ.ॱˊ() == 0) {
            ᐝ();
        } else if (this.ʽ.ॱˊ() == 1) {
            ʼ();
            this.ॱ.setText(j.ᐝ);
        } else if (this.ʽ.ॱˊ() == 2) {
            ʼ();
            this.ॱ.setText(j.ʻ);
        } else if (this.ʽ.ॱˊ() == 3) {
            ˎ(j.ॱॱ, j.ˏॱ, j.ॱ);
        } else if (this.ʽ.ॱˊ() == 4) {
            ˎ(j.ʽ, j.ʼ, j.ʼ);
        }
    }

    private void ᐝ() {
        String ॱ = this.ʽ.ॱ();
        if (ॱ == null) {
            this.ॱ.setVisibility(8);
            return;
        }
        List ॱॱ = this.ʽ.ॱॱ();
        if (ॱॱ != null && ॱॱ.size() > 0) {
            ˋ(ॱॱ);
        }
        ˎ(ॱ);
    }

    private void ˎ(int i, int i2, int i3) {
        ʼ();
        if (this.ʻ == 1) {
            this.ॱ.setText(i);
        } else if (this.ʻ == 2 || this.ʻ == 3) {
            this.ॱ.setText(i2);
        } else if (this.ʻ == 4 || this.ʻ == 5) {
            this.ॱ.setText(i3);
        }
    }

    private void ˎ(String str) {
        SpannableStringBuilder spannableStringBuilder;
        this.ॱ.setTextColor(ContentManager.getInstant().getContext().getResources().getColor(a.ˏ));
        if ("".equals(str) && this.ˏॱ) {
            spannableStringBuilder = new SpannableStringBuilder(this.ʼॱ.getResources().getString(bqz.d.ˋˊ));
        } else {
            String replace = str.replace("[br]", "\n");
            ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ContentManager.getInstant().getContext().getResources().getColor(a.ˊ));
            CharSequence format = String.format(Locale.ENGLISH, this.ʼॱ.getResources().getString(j.ˑ), new Object[]{replace});
            int lastIndexOf = format.lastIndexOf(replace);
            spannableStringBuilder = new SpannableStringBuilder(format);
            try {
                spannableStringBuilder.setSpan(foregroundColorSpan, 0, lastIndexOf, 17);
                if (this.ʻ == 1) {
                    spannableStringBuilder.replace(lastIndexOf, replace.length() + lastIndexOf, btu.ॱ(this.ʼॱ, replace, btu.ˏ()));
                }
            } catch (Exception e) {
                bqx.ॱ("ForumRemindCommentCard", "setSpan error");
            }
        }
        this.ॱ.setOnContentChangedListener(new e(this) {
            final /* synthetic */ ForumRemindCommentCard ˋ;

            {
                this.ˋ = r1;
            }

            public void ˎ(boolean z) {
                if (this.ˋ.ˏॱ || z) {
                    this.ˋ.ˎ.setVisibility(0);
                } else {
                    this.ˋ.ˎ.setVisibility(8);
                }
                this.ˋ.ˏॱ();
            }
        });
        this.ॱ.setMovementMethod(LinkMovementMethod.getInstance());
        this.ॱ.setContent(spannableStringBuilder, this.ᐝ.ʽ(), ((azb.ॱ(this.ʼॱ) - this.ʼॱ.getResources().getDimensionPixelSize(cbb.e.ˋॱ)) - azb.ˏ(this.ʼॱ)) - azb.ᐝ(this.ʼॱ));
    }

    private void ˋ(List<ImageInfo> list) {
        this.ˎ.setVisibility(0);
        ˏॱ();
        if (this.ᐝ.ʽ()) {
            this.ˊ.setVisibility(0);
        } else {
            this.ˊ.setVisibility(8);
        }
        String ˊ = TextUtils.isEmpty(((ImageInfo) list.get(0)).ˋ()) ? ((ImageInfo) list.get(0)).ˊ() : ((ImageInfo) list.get(0)).ˋ();
        ˋ(this.ˊ, (int) (((float) ((azb.ॱ(ˉ().getContext()) - azb.ˏ(this.ʼॱ)) - azb.ᐝ(this.ʼॱ))) - ˉ().getContext().getResources().getDimension(d.ˊॱ)), ˊ, ((ImageInfo) list.get(0)).ˎ(), ((ImageInfo) list.get(0)).ˏ());
        ॱ(this.ˊ, ˊ);
        this.ˏॱ = true;
    }

    private void ˋ(ImageView imageView, int i, String str, int i2, int i3) {
        Object obj = null;
        if (bsx.ˎ(str)) {
            obj = 1;
        }
        LayoutParams layoutParams = imageView.getLayoutParams();
        if (i2 <= 0 || i3 <= 0) {
            layoutParams.width = i;
            layoutParams.height = (int) (0.5f * ((float) i));
        } else {
            float f = ((float) i3) / ((float) i2);
            if (obj == null) {
                layoutParams.width = i;
                layoutParams.height = (int) (((float) i) * f);
            } else if (i2 < i) {
                layoutParams.width = i2;
                layoutParams.height = (int) (((float) i2) * f);
            } else {
                layoutParams.width = i;
                layoutParams.height = (int) (((float) i) * f);
            }
        }
        imageView.setLayoutParams(layoutParams);
    }

    private void ॱ(ImageView imageView, String str) {
        if (imageView != null && !TextUtils.isEmpty(str)) {
            LayoutParams layoutParams = imageView.getLayoutParams();
            if (layoutParams.height > 4096) {
                imageView.setScaleType(ScaleType.FIT_START);
                layoutParams.height = 4096;
                imageView.setLayoutParams(layoutParams);
            }
            if (bsx.ˎ(str)) {
                eqx.ˎ(imageView, str, "image_default_icon");
            } else {
                eqx.ˏ(imageView, str, "image_default_icon");
            }
        }
    }

    private void ʼ() {
        int i = 1;
        Drawable drawable = this.ʼॱ.getResources().getDrawable(c.ॱˋ);
        drawable.setBounds(0, 0, 64, 64);
        this.ॱ.setTextColor(ContentManager.getInstant().getContext().getResources().getColor(a.ˊ));
        if (hb.ˎ(Locale.getDefault()) != 1) {
            i = 0;
        }
        if (i != 0) {
            this.ॱ.setCompoundDrawables(null, null, drawable, null);
        } else {
            this.ॱ.setCompoundDrawables(drawable, null, null, null);
        }
        this.ॱ.setCompoundDrawablePadding(8);
    }

    public void onClick(View view) {
        if (b.ʻˊ == view.getId()) {
            ˋॱ();
        }
    }

    private void ˋ(View view) {
        if (this.ʽ == null) {
            evk.ˏ(this.ʼॱ.getString(bse.ˏ.ॱ(400012).ˏ()));
        } else if (this.ʽ.ॱˊ() == 4) {
            evk.ˏ(view.getContext(), j.ˋ, 0).ˋ();
        } else if (this.ʽ.ॱˊ() == 3) {
            evk.ˏ(view.getContext(), j.ˎ, 0).ˋ();
        } else if (this.ᐝ.ʼ() == null || this.ᐝ.ʼ().ˊ() != 1) {
            ʻ();
        } else {
            evk.ˏ(this.ʼॱ.getString(bse.ˏ.ॱ(400006).ˏ()));
        }
    }

    private void ʻ() {
        if (this.ʽ.ॱˊ() == 1) {
            evk.ˏ(this.ʼॱ.getString(bse.ˏ.ॱ(400006).ˏ()));
        } else if (this.ʽ.ॱˊ() == 2) {
            evk.ˏ(this.ʼॱ.getString(bse.ˏ.ॱ(400007).ˏ()));
        } else if (this.ʽ.ॱˊ() == 3) {
            evk.ˏ(this.ʼॱ.getString(bse.ˏ.ॱ(400008).ˏ()));
        } else if (this.ʽ.ॱˊ() == 4) {
            evk.ˏ(this.ʼॱ.getString(bse.ˏ.ॱ(400011).ˏ()));
        } else if (this.ʽ.ॱˊ() == 0) {
            ͺ();
        }
    }

    private void ͺ() {
        if (this.ʻ == 2 || this.ʻ == 3) {
            if (this.ॱˊ == 0) {
                String ͺ = this.ʽ.ͺ();
                if (ͺ != null && ͺ.contains("post_detail|")) {
                    String[] split = ͺ.split("[|]");
                    if (split.length >= 3) {
                        ͺ = split[2];
                        if (TextUtils.isEmpty(ͺ) || !ͺ.contains(",cid_")) {
                            this.ॱˊ = Long.parseLong(ͺ);
                        } else {
                            this.ॱˊ = Long.parseLong(ͺ.substring(0, ͺ.indexOf(",cid_")));
                        }
                    } else {
                        return;
                    }
                }
            }
            bwy.ˏ().ॱ(this.ʼॱ, this.ॱॱ, this.ʻ, this.ॱˊ, this.ͺ);
        } else if (this.ʻ == 4 || this.ʻ == 5) {
            bwy.ˏ().ˊ(this.ʼॱ, this.ॱॱ, this.ʻ, this.ˋॱ, this.ʽ.ˏॱ(), this.ͺ);
        } else {
            bwy.ˏ().ॱ(this.ʼॱ, this.ॱॱ, this.ʻ, this.ʽ.ˏ(), this.ͺ);
        }
    }

    private void ˋॱ() {
        if (this.ᐝ.ʽ()) {
            this.ˊ.setVisibility(8);
            this.ˎ.setText(j.ˋˋ);
            this.ᐝ.ˏ(false);
        } else {
            if (this.ˏॱ) {
                this.ˊ.setVisibility(0);
            }
            this.ˎ.setText(j.ʿ);
            this.ᐝ.ˏ(true);
        }
        this.ॱ.ˎ();
    }

    public void ʽॱ() {
    }

    public void ॱ(boolean z) {
        if (this.ʽ != null) {
            String ͺ = this.ʽ.ͺ();
            if (!TextUtils.isEmpty(ͺ)) {
                cil.ˋ(this.ʼॱ, new cim.a().ˊ(ͺ).ˋ());
                if (!ͺ.contains("app_detail_comment") && !ͺ.contains("app_detail_reply")) {
                    bwy.ˏ().ˋ(this.ʼॱ, this.ʽ.ͺ(), 0, this.ͺ);
                } else if (this.ʽ.ॱˊ() != 4) {
                    bwy.ˏ(this.ʼॱ, ͺ);
                }
            }
        }
    }

    private void ˏॱ() {
        if (this.ᐝ.ʽ()) {
            this.ˎ.setText(j.ʿ);
        } else {
            this.ˎ.setText(j.ˋˋ);
        }
    }
}
